package com.yuanzong.wuliu.service.app.base;

import com.yuanzong.wuliu.common.exception.BusinessException;
import com.yuanzong.wuliu.common.utils.code.PhotoCodeUtils;
import com.yuanzong.wuliu.common.vo.ApiResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Service()
public class AppCodeService {

    public ApiResult photo(String photoCodeKey) throws Exception {
        // 整体参数验证
        if (StringUtils.isEmpty(photoCodeKey)) {
            throw new BusinessException("参数不能为空");
        }
        Map codeMap = PhotoCodeUtils.generateCaptchaBase64();
        String value = codeMap.get(PhotoCodeUtils.CODE_VALUE).toString();
        // 保存验证码信息,存入Map
        PhotoCodeUtils.photoCodeMap.put(photoCodeKey, value);
        // 图片base返回
        String base64 = codeMap.get(PhotoCodeUtils.CODE_BASE64).toString();
        return ApiResult.success(base64);
    }

}
